import { Component, Input, OnInit } from '@angular/core';
import { ColumnType, SPage } from '@shared/components/table-page/table-page.component';
import { ApiService } from '@core/services/api';
import { _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd';
import { UtilService } from '@core/services/util.service';
import { CensusType, IdCardType, MartialStatus } from '@core/config/dic.config';
import { environment } from '@env/environment';

@Component({
  selector: 'app-people-detail',
  templateUrl: './people-detail.component.html',
  styleUrls: ['./people-detail.component.less'],
})
export class PeopleDetailComponent implements OnInit {
  @Input()
  set _param(value) {
    this.param = value;
    this.getPeopleInfo(value.peopleId || value.id);
    this.getCardList(value.peopleId || value.id);
  }
  imgUrl = environment.SERVER_URL + '/';
  param: any;
  // 人员信息数据
  controlArray = [
    {
      title: '姓名',
      index: 'infoName',
    }, {
      title: '性别',
      index: 'infoSex', items: this.util.getObjDic('XB')
    }, /*{
      title: '人员类型',
      index: 'status',
    },*/
    {
      title: '出生日期',
      index: 'infoBirthday',
    }, {
      title: '民族',
      index: 'infoNation',
    }, {
      title: '籍贯',
      index: 'infoNativePlace',
    },
    {
      title: '户籍地址',
      index: 'infoNativeAddress',
    }, {
      title: '婚姻状况',
      index: 'infoMaritalStatus',
      items: this.util.getObjDic("HYZK")
    }, {
      title: '手机号码',
      index: 'infoMobile',
    },
    {
      title: '手机号码2',
      index: '',
    },
    {
      title: '居住类型',
      index: 'infoDwellType',
      items: this.util.objToMap('JZLX')
    },
    {
      title: '户籍地址类型',
      index: 'infoHouseAddressType',
      items: this.util.objToMap('HJLX')
    },
    {
      title: '户籍地址区域',
      index: ''
    },
    {
      title: '证件类型',
      index: 'infoIdcardType',
      items: this.util.getObjDic('ZJLX')
    },
    {
      title: '证件号码',
      index: 'infoIdcardNumber'
    },
    {
      title: '证件签发机关',
      index: 'infoAuthority'
    },
    {
      title: '证件有效期起',
      index: 'infoValidPeriod'
    },
    {
      title: '证件有效期止',
      index: 'infoValidTill'
    },
    {
      title: '服务处所',
      index: 'infoCompanyName'
    },
    {
      title: '在深户主姓名',
      index: 'roomOwerName'
    },
    {
      title: '户主证件号码',
      index: 'roomOwerIdcard'
    },
    {
      title: '与户主关系',
      index: 'roomOwerRelation'
    },
    {
      title: '来深事由',
      index: 'infoLsReason'
    },
    {
      title: '紧急联系电话',
      index: 'infoEmergencyMobile'
    },
    {
      title: '入住时间',
      index: 'roomInTime'
    },
    {
      title: '职业',
      index: ''
    },
    {
      title: '文化程度',
      index: 'infoCulture'
    }
  ];

  Config: SPage = {
    columns: [
      {
        index: 'roomAddress',
        title: '楼宇位置',
      },
      {
        index: 'hostId',
        title: '主机串号',
      },
      {
        index: 'status',
        title: '权限状态',
      },

    ],
    data: [],
  };

  constructor(
    private api: ApiService,
    private http: _HttpClient,
    private msg: NzMessageService,
    private util: UtilService
  ) {
  }

  ngOnInit() {
    this.util.getDicByField('xb').subscribe(res => console.log(res))
  }

  getPeopleInfo(id: string): void {
    this.http.request<any>(this.api.peopleInfo.page.method, this.api.peopleInfo.page.url, { body: { id } }).subscribe(res => {
      if (res.status === '200' && res.data.list.length > 0) {
        this.param = res.data.list[0];
      } else {
        this.msg.error('未查询到人员信息');
      }
    });
  }

  /**
   * 获取人员绑定门卡信息
   * @param id peopleid
   */
  getCardList(id: string): void {
    this.http.request<any>(this.api.peopleInfo.cardList.method, `${this.api.peopleInfo.cardList.url}/${id}`).subscribe(res => {
      if (res.status === '200') {
        console.log(res);
      }
    });
  }
}
